package com.dg11185.nearshop.activity;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.nearshop.R;
import com.wlper.lib.uitls.ViewUtils;

/**
 * 模板Activity，一级页面
 * 
 * @author wanliang527
 * 
 */
public class PrimaryLevelActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initTopBanner();
    }

    protected void initTopBanner() {
        LinearLayout leftView = getPartView(LEFT);
        ImageView titleIcon = new ImageView(this);
        titleIcon.setBackgroundResource(R.drawable.icon_title);
        leftView.addView(titleIcon);
        ((LinearLayout.LayoutParams) titleIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL;

        LinearLayout rightView = getPartView(RIGHT);
        Button shakeBtn = new Button(this);
        shakeBtn.setTag("shake");
        shakeBtn.setOnClickListener(clickListener);
        shakeBtn.setBackgroundResource(R.drawable.ic_shake_p1);
        rightView.addView(shakeBtn);

        Button searchBtn = new Button(this);
        searchBtn.setTag("search");
        searchBtn.setOnClickListener(clickListener);
        searchBtn.setBackgroundResource(R.drawable.selector_search_btn2);
        rightView.addView(searchBtn);
        ((LinearLayout.LayoutParams) searchBtn.getLayoutParams()).leftMargin = 20;

    }

    private View.OnClickListener clickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = (String) v.getTag();
            if (tag.equals("shake")) {
                ViewUtils.showToast(PrimaryLevelActivity.this, "跳到摇摇界面");
            } else if (tag.equals("search")) {
                ViewUtils.showToast(PrimaryLevelActivity.this, "跳到搜索界面");
            }
        }
    };

}
